<template>
  <div class="viewContain">
    <el-row>
      <el-col :xs="{ span: 24 }" :sm="{ span: 12 }" :md="{ span: 8 }" :xl="{ span: 8 }">
        <el-button type="primary" size="mini" @click="handleBack">返回</el-button>
        <span>软件版本操作记录窗口</span>
      </el-col>
    </el-row>
    <el-table
      fit
      stripe
      border
      :data="versionLogs"
      style="margin-top:20px"
    >
      <el-table-column align="center" label="序号" type="index" width="50">
        <template slot-scope="scope">
          {{ scope.$index+1 }}
        </template>
      </el-table-column>
      <el-table-column property="name" label="版本名称" width="180" align="center" />
      <el-table-column property="versionId" label="版本号" width="70" align="center" />
      <el-table-column property="optUser" label="操作人" align="center" />
      <el-table-column property="optType" label="操作类型" align="center" />
      <el-table-column property="optTime" label="操作时间" align="center" />
      <el-table-column property="optionDescription" label="操作内容" align="center" />
    </el-table>
  </div>
</template>

<script>
import { handleVersionLogs } from '@a/software/software.js'
export default {
  data() {
    return {
      listQuery: {
        pageNo: 1,
        pageSize: 10
      },
      versionLogs: [{
        name: '',
        optTime: '',
        optType: '',
        optUser: '',
        optionDescription: '',
        versionId: ''
      }]
    }
  },
  mounted() {
    const userId = this.$route.params.userId
    const name = this.$route.params.name
    console.log(userId)
    console.log(name)
    handleVersionLogs(userId).then(res => {
      if (res.code === 0) {
        this.versionLogs = res.data.list
        this.versionLogs.forEach((item, index) => {
          item.optTime = this.timestampToTime(item.optTime)
          item.name = name
        })
      } else {
        this.$message({
          type: 'error',
          message: res.message
        })
      }
    })
  },
  methods: {
    handleBack() {
      this.$store.dispatch('tagsView/delVisitedView', this.$route)
      this.$router.go(-1)
    },
    // 时间戳转换为date
    timestampToTime(timestamp) {
      var date = new Date(timestamp) // datetime时间戳为13位毫秒级别,如为10位需乘1000
      var month = ('0' + (date.getMonth() + 1)).slice(-2)	// getMonth是从1-11,所以需要加1
      var sdate = ('0' + date.getDate()).slice(-2)	// -2表示从倒数第二个元素开始截取
      var hour = ('0' + date.getHours()).slice(-2)
      var minute = ('0' + date.getMinutes()).slice(-2)
      var second = ('0' + date.getSeconds()).slice(-2)
      var thatDate = date.getFullYear() + '-' + month + '-' + sdate + ' ' + hour + ':' + minute + ':' + second
      // 返回
      return thatDate
    }
  }
}
</script>

<style lang="scss" scoped>
</style>
